/**
 * LogCashService.java
 * Copyright(C) 1949++ 中华人民共和国
 * 深圳市盛开互联网金融顾问有限公司.
 * All rights reserved.
 * E-mail:server@skjr.net
 * SKDate:2017-11-16 17:28:58
 */
package com.huamao.zh.service.impl;

import java.math.BigDecimal;
import java.util.Date;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.huamao.zh.base.PageWrapper;
import com.huamao.zh.constants.CashType;
import com.huamao.zh.mapper.LogCashMapper;
import com.huamao.zh.model.LogCash;
import com.huamao.zh.service.LogCashService;

@Service
@Transactional
public class LogCashServiceImpl implements LogCashService {

	@Autowired
	private LogCashMapper logCashMapper;

	/**
	 * 功能说明： Author： SKDate:2017-11-16 17:28:58
	 */
	public LogCash add(LogCash logCash) throws Exception {
		logCashMapper.add(logCash);
		return logCash;
	}

	/**
	 * 功能说明：记录现金流水日志 -- 增加专用 Author：spring Date：2017/11/20 15:00
	 */
	@Override
	public LogCash sumCash(CashType type, Integer fromId, Integer userId, String orderNo, BigDecimal preCash,
			BigDecimal cash, String remark) throws Exception {

		LogCash logCash = new LogCash();
		logCash.setType(type.getCode());
		logCash.setFromId(fromId);
		logCash.setUserId(userId);
		logCash.setOrderNo(orderNo);
		logCash.setPreCash(preCash);
		logCash.setCashType(1);
		logCash.setCash(cash);
		logCash.setRemark(remark);
		logCash.setDataFlag(1);
		logCash.setCreateTime(new Date());

		return this.add(logCash);
	}

	/**
	 * 功能说明：记录现金流水日志 -- 扣减专用 Author：spring Date：2017/11/20 15:03
	 */
	@Override
	public LogCash subtractCash(CashType type, Integer fromId, Integer userId, String orderNo, BigDecimal preCash,
			BigDecimal cash, String remark) throws Exception {
		LogCash logCash = new LogCash();
		logCash.setType(type.getCode());
		logCash.setFromId(fromId);
		logCash.setUserId(userId);
		logCash.setOrderNo(orderNo);
		logCash.setPreCash(preCash);
		logCash.setCashType(0);
		logCash.setCash(cash);
		logCash.setRemark(remark);
		logCash.setDataFlag(1);
		logCash.setCreateTime(new Date());
		return this.add(logCash);
	}

	/**
	 * 功能说明： Author： SKDate:2017-11-16 17:28:58
	 */
	public LogCash addSelective(LogCash logCash) throws Exception {
		logCashMapper.addSelective(logCash);
		return logCash;
	}

	/**
	 * 功能说明： Author： SKDate:2017-11-16 17:28:58
	 */
	public int delete(Map<String, Object> map) {
		return logCashMapper.delete(map);
	}

	/**
	 * 功能说明： Author： SKDate:2017-11-16 17:28:58
	 */
	public int update(LogCash logCash) throws Exception {
		return logCashMapper.update(logCash);
	}

	/**
	 * 功能说明： Author： SKDate:2017-11-16 17:28:58
	 */
	public int updateSelective(LogCash logCash) throws Exception {
		return logCashMapper.updateSelective(logCash);
	}

	/**
	 * 功能说明： Author： SKDate:2017-11-16 17:28:58
	 */
	public LogCash get(Integer id) {
		LogCash logCash = logCashMapper.get(id);
		return logCash;
	}

	/**
	 * 功能说明： Author： SKDate:2017-11-16 17:28:58
	 */
	public PageWrapper<LogCash> search(PageWrapper<LogCash> pageWrapper) {
		List<LogCash> logCashs = logCashMapper.search(pageWrapper);
		pageWrapper.setList(logCashs);
		return pageWrapper;
	}

	/**
	 * 功能说明： Author： SKDate:2017-11-16 17:28:58
	 */
	public List<LogCash> queryList(Map<String, Object> map) {
		return logCashMapper.queryList(map);
	}
}